using BuildingBlocks.Presentation.Endpoints;
using BuildingBlocks.Presentation.Results;
using Mediator;
using Ordering.Application.Orders.GetOrders;

namespace Ordering.Api.Endpoints.Orders;

internal sealed class GetOrdersEndpoint : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet($"{OrderRoutes.Base})",
                async (IMediator mediator, CancellationToken cancellationToken) =>
                {
                    var result = await mediator.Send(new GetOrdersQuery(), cancellationToken);
                    return result.Match(Results.Ok, ApiResponse.Problem);
                })
            .WithName("GetOrders")
            .WithTags("Orders");
    }
}
